package greetings

import (
	"fmt"
	"errors"
	"math/rand"
)


func Hello(name string) (string,error) {
	if name == "" {
        return name, errors.New("empty name")
    }
    // Create a message using a random format.
    // message := fmt.Sprintf(randomFormat(), name)
    message := fmt.Sprint(randomFormat())
    return message, nil
}
func Hellos(names []string) (map[string]string,error){
	messages := make(map[string]string)
	for _, name := range names {
		message, err := Hello(name)
		if err != nil {
			return nil, err
		}
		messages[name] = message
	}
	return messages,nil
}
func randomFormat() string {
	formats := []string{
		"Hi, %v. Welcome!",
		"Great to see you, %v!",
		"Nice to meet you, %v!",
	}
	// fmt.Println(rand.Intn(len(formats)))
	return formats[rand.Intn(len(formats))]
}